package executor;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author lwj
 * @date 2025-03-10
 * @vesion 1.0.0
 */
public class MainTest {
    public static void main(String[] args) {
        // 第二：工具类 Executors 创建线程池并返回 ExecutorService 对象
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        // 第三：创建 Future 对象
        Future<String> future = executorService.submit(new MyCallable());

        // 第四：获取值 - 主线程进行阻塞状态
        try {
            String msg = future.get();
            System.out.println(msg);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }

        // 第五：停止服务
        executorService.shutdownNow();

        System.out.println("主线程的一些处理");
    }
}
